<div id="log_info">
  <%= render :layout => '/login/log_info' %>
</div>

<br/><br/><br/>
<div align="center" >
  <img src="../../images/main.jpg" id="picture" />   <!--插入网站主页的大图-->
</div>

<div id="function">
  <table width="500" border="0">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</div>


<div class="section">
 <div class="item">
   <h3><%= @topic.title %></h3>
     <div class="type">帖子种类:
       <% topic_type = Activity.find_by_id( @topic.id ) ? "活动帖" : "讨论帖" %>
       <%=h topic_type %>
     </div>

     <div class="description">帖子内容：<%=h @topic.topic_content%></div>
       <% if topic_type == "活动帖" %>
         <% activity = Activity.find( @topic.id ) %>
         <% if (activity.state == "招募中" && activity.deadline < Time.now) || activity.people_demande == 0 && activity.state == "招募中" %>
           <% activity.state = "进行时" %>
           <% activity.save %>
         <%  elsif @user && activity.volunteers.find_by_account(@user.account) %>
           <% activity.state = "已报名" %>
         <% end %>
       <div> state：<%=h activity.state %> </div>
       <% if @user && activity.state == "招募中" %>
          需求人数  ：<%=h activity.people_demande + activity.volunteers.count %>&nbsp;&nbsp;&nbsp;
          剩余名额  ：<%=h activity.people_demande %> &nbsp;&nbsp;&nbsp;
          <% if @user && @user.permission == 2 %>
             <% form_remote_tag :url=>{ :controller=>"activity", :action=>"enroll", :id=>@topic.id } do  %>
             <%= submit_tag " 我要报名 " %>
             <% end %>
          <% end %>
        <% end %>
       <% end %>

<div class="post">
   <table width="500" border="0">
     <tr>
       <td><img src="../../images/starter.jpg"/> 发帖人 ：<%=h @topic.user.account %></td>
       <td><img src="../../images/time.jpg"/>   发帖时间 ：<%=h @topic.created_at %></td>
     </tr>
   </table>
</div>


<div class="p">
  <table width="240" border="0">
    <tr>
      <td>
         <% if @user && @user.permission == 4 %>
            <%= button_to " 删帖 ", :controller=>"topics", :action=>"destroy", :id=>@topic.id  %>
         <% end %>
      </td>
     </tr>
   </table>
</div>

 </div>
 </div>


        <% @floor = 0 %>
         <% @comments.each do |comment| %>
  	<div class="section">
          <div class="reply">

                     <div ><%= @floor=@floor+1 %>#</div>
                     <div class="description"> <%=h comment.comment_content %><p></p></div>
                     <div class="post">
   <table width="500" border="0">
     <tr>
       <td><img src="../../images/starter.jpg"/>回复人：<%=h comment.user.account %></td>
       <td>          <img src="../../images/time.jpg"/>回复时间：<%=h comment.created_at %></td>
   </tr>
   </table>
                     </div>
                     <div class="p">
        <table width="240" border="0">
  	  <tr>
    	    <td>
              <% if @user && @user.permission == 4 %>
                <%= button_to " 删除回复 ", :controller=>"comment", :action=>"destroy", :comment_id=>comment.id, :topic_id=>@topic.id  %>
              <% end %>
            </td>
          </tr>
        </table>
      </div>
          </div>
         </div>
         <%end%>

<% if @user && @user.permission > 0 %>
<div class="section">
    		<div class="item">
      			<h3>添加回复</h3>

      			<div class="description">
                          <% form_for @new_comment,:url=>{ :controller=>"topics", :action=>"add_new_comment", :topic_id=> @topic.id } do |f|  %>
                          <%= f.text_area :comment_content, :cols=>120, :rows=>8 %>
                          <%= f.submit " 提交 " %>
                          <% end  %>
                        </div>

    		</div>
  		</div>
<div id="footer">
</div>
<%  end %>